package com.ruipeng.shengyapo.utils;
import java.io.Serializable;
import java.util.HashMap;

import net.sf.json.JSONObject;


public class YunBa implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = -7266993207101011341L;
	private static String method = "publish";
	private static String appkey = "59354febc714b4903f936f9f";
	private static String seckey = "sec-Jg24PIulKnksnqcml3EhrxME07uhoQ2ntNMWNlUnKdO5WMGw";
	//private static String topic ;//别名
	//private static String msg;//广播内容
	//private static Object opts;
	public static String url="http://rest.yunba.io:8080/";

	public static  String yunbaUtil(){
		HashMap<String,Object> resutMap=new HashMap<String,Object>();
		resutMap.put("topic", "#topic");
		resutMap.put("appkey",appkey);
		resutMap.put("seckey", seckey);
		resutMap.put("method", method);

		HashMap<String,Object> map=new HashMap<String,Object>();
		HashMap<String,Object> cmap=new HashMap<String,Object>();
			cmap.put("alert", "#alert");
			cmap.put("badge", 1);
			cmap.put("sound","bingbong.aiff");
			HashMap<String,Object> ccMap=new HashMap<String,Object>();
			ccMap.put("aps", cmap);
			ccMap.put("type","#type");
			map.put("apn_json", ccMap);
			resutMap.put("opts", map); 	
			resutMap.put("msg", map);
		 url = "http://rest.yunba.io:8080/";
		JSONObject json = JSONObject.fromObject(resutMap);
		return json.toString();
		//System.out.println(HttpUtils.sendPost(url, json.toString()));
	}
	
	
	public static void main(String[] args) {
//		YunBa vo  = new YunBa();
//		vo.setTopic("#topic");
//		vo.setMsg("yunba1");
//
//		HashMap<String,Object> map=new HashMap<String,Object>();
//		HashMap<String,Object> cmap=new HashMap<String,Object>();
//			cmap.put("alert", "#alert");
//			cmap.put("badge", 1);
//			cmap.put("sound","bingbong.aiff");
//			HashMap<String,Object> ccMap=new HashMap<String,Object>();
//			ccMap.put("aps", cmap);
//			ccMap.put("type","#type");
//			map.put("apn_json", ccMap);
//		vo.setOpts(map);				
//		 url = "http://rest.yunba.io:8080/";
//		JSONObject json = JSONObject.fromObject(vo);
//		System.out.println(json);
		String tsStr= YunBa.yunbaUtil(); 
		tsStr=tsStr.replace("#topic","Topic_User_1_"+4);
		tsStr=tsStr.replace("#alert","您有一条订单消息");
		tsStr=tsStr.replace("#type","1");
		System.out.println(HttpUtils.sendPost(YunBa.url, tsStr.toString()));
		System.out.println(tsStr);
	}
}
